import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    dialogVisible: false,
    centerDialogVisible: false,
    mima: '2323423',
    input: '',
    updateData: {},
    newsList: [{}],
    newdata: {}
  },
  mutations: {// 更改共享状态的方法
    doChange(state, payload) {

      // debugger
      // if (payload.hasOwnProperty('name')) {
      //   state.name = payload.name
      // }
    },
    chushua(state, payload) {
      state.newsList = payload.data
      console.log(state.newsList, '2')
    },
    xiugai(state, payload) {
      state.updateData = payload.data
      console.log(state.updateData)
    },
    ok(state, payload) {
      debugger
      for (let i = 0; i < payload.data.length; i++) {
        const list = payload.data[i]
        if (list.number === this.updateData.number) {
          state.newdata[i] = this.updateData
          Vue.set(this.payload.data, i, this.payload.data[i])
          this.$notify({
            title: '修改成功',
            message: '修改成功',
            type: 'success'
          })
        }
      }
    }

  },
  actions: {// 在需要封装多个Mutation方法时，使用
    doActionChange(context) {
      context.commit('doChange')
      context.commit('doChange2')
    }
  }
})
